<?php

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $user = \App\User::where('name', 'admin@admin')->first();
        if (empty($user)) {
            $user = new \App\User();
            $user->name = 'admin';
            $user->email = 'admin@admin';
            $user->password = bcrypt('123456');
            $user->save();
            $role = \Spatie\Permission\Models\Role::create(['name' => '超级管理员', 'guard_name' => 'admin']);
            $user->assignRole($role->name);
        }
        if ($role) {
            Permission::create(['name' => '用户管理', 'guard_name' => 'admin']);
            Permission::create(['name' => '角色管理', 'guard_name' => 'admin']);
            Permission::create(['name' => '微信用户', 'guard_name' => 'admin']);
            Permission::create(['name' => '教师管理', 'guard_name' => 'admin']);
            Permission::create(['name' => '分类管理', 'guard_name' => 'admin']);
            Permission::create(['name' => '课程管理', 'guard_name' => 'admin']);
            Permission::create(['name' => '销售榜单', 'guard_name' => 'admin']);
            Permission::create(['name' => '订单管理', 'guard_name' => 'admin']);
            Permission::create(['name' => '文件管理', 'guard_name' => 'admin']);
            Permission::create(['name' => '云存储', 'guard_name' => 'admin']);
            Permission::create(['name' => '微信配置', 'guard_name' => 'admin']);
            Permission::create(['name' => '广告配置', 'guard_name' => 'admin']);
            $permissions = Permission::all();
            $role->syncPermissions($permissions->pluck('id')->toArray());
        }

    }
}
